# configure.ac
#
# This file is processed by autoconf to generate a configure script.
# the configure script is then used to configure the daagt application.
#
AC_INIT([ConArtist], [0.0.1])
AC_CONFIG_HEADER([include/config.h])
AM_INIT_AUTOMAKE

# dnl include our homebrew scripts
sinclude(build/apr.m4)
sinclude(build/httpd.m4)
sinclude(build/svn.m4)
sinclude(build/xslt.m4)

srcdir=`pwd`
topdir=`pwd`

AC_ARG_WITH(cflags,
        [  --with-cflags           Specify additional flags to pass to preprocessor] ,
        [
                if test "x$withval" != "xno"; then
                        CFLAGS="$CFLAGS $withval"
                fi
        ]
)
AC_ARG_WITH(cppflags,
        [  --with-cppflags         Specify additional flags to pass to preprocessor] ,
        [
                if test "x$withval" != "xno"; then
                        CPPFLAGS="$CPPFLAGS $withval"
                fi
        ]
)

SO_EXT=so
SO_FLAGS="-shared"
SO_NAME="-Wl,-soname,lib\$(MODULE).\$(SO_EXT)"
PICFLAGS="-fPIC -DPIC"
OS=`uname -s`

case $OS in 
    Darwin*)
        SO_FLAGS="-dynamiclib"
        SO_NAME="-install_name \$(MODDIR)/lib\$(MODULE).\$(SO_EXT)"
        ;;
    SunOS*)
        PICFLAGS="-Kpic"
        SO_FLAGS="-G"
        SO_NAME=""
        ;;
    *) ;;
esac

# Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_RANLIB

# Check for httpd, APR and Subversion
CA_CHECK_HTTPD
CA_CHECK_APR
CA_CHECK_APU
CA_CHECK_SVN
CA_CHECK_XSLT

# Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS([stddef.h string.h sys/param.h unistd.h limits.h syslog.h])

# Check for OpenSSL
AC_CHECK_HEADER(openssl/x509.h)
AC_CHECK_LIB(crypto, BN_init)
AC_CHECK_LIB(ssl, SSL_accept)

AM_PATH_XML2(2.6.11,
    ,
    AC_MSG_ERROR([could not find libxml2])
)
XML_LIBDIR="`echo $XML_LIBS | sed -e 's/^\-L//' | sed -e 's/ -l.*$//'`"

# Checks for library functions.
AC_FUNC_ALLOCA
AC_FUNC_MALLOC
AC_FUNC_STAT
AC_FUNC_STRFTIME
AC_CHECK_FUNCS([memset strchr strdup strstr realpath])
AC_CHECK_FUNCS([strlcpy strlcat])
AC_CHECK_DEFINE([_PASSWORD_LEN], [pwd.h])

AC_DEFINE([HAVE_SA_LEN], [], 
          [Defined if sockaddr structure has sa_len field])
AC_MSG_CHECKING(for sa_len in struct sockaddr)
AC_TRY_COMPILE([#include <sys/types.h>
#include <sys/socket.h>], [struct sockaddr s; s.sa_len;], [
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_SA_LEN)
], [
AC_MSG_RESULT(no)
],
[Whether the sockaddr structure has an sa_len member])

# We substitute the following variables...
AC_SUBST(OS)
AC_SUBST(PLATFORM)
AC_SUBST(CFLAGS)
AC_SUBST(topdir)
AC_SUBST(CPPFLAGS)
AC_SUBST(SHARED_FLAGS)
AC_SUBST(SO_FLAGS)
AC_SUBST(SO_EXT)
AC_SUBST(PICFLAGS)
AC_SUBST(SO_NAME)
AC_SUBST(XML_LIBDIR)

AC_CONFIG_FILES([Makefile
                 build/settings
		 doxygen.conf
                 lib/Makefile
                 mod_conartist/Makefile
                 pipes/xslt/Makefile
                 stores/local/Makefile
                 stores/svn_remote/Makefile
                 tests/Makefile
                 svn_notifier/Makefile
		 tests/testConfig.xml
                 pipes/xml/Makefile
])

AC_OUTPUT
